package org.zjx.strategy.impl;

import org.zjx.action.Action;
import org.zjx.action.basic.DelayAction;
import org.zjx.action.game.gather.GatherPetAction;
import org.zjx.action.game.gather.GatherPropAction;
import org.zjx.action.game.gather.GatherRoleAction;
import org.zjx.action.game.gather.GatherTaskBoxAction;
import org.zjx.action.service.AccountAction;
import org.zjx.core.IWindow;
import org.zjx.core.impl.GameWindow;
import org.zjx.state.*;
import org.zjx.strategy.IStrategy;

public class InitStrategy implements IStrategy {

    @Override
    public Action analyze(IWindow window) {
        if (window.getState().getState(AccountState.class) == null) {
            return new AccountAction(window);
        }

        GameState gameState = window.getState().getGameState();
        if (!gameState.isGatherRole()) {
            return new GatherRoleAction(window);
        }

        if (!gameState.isGatherPet()) {
            return new GatherPetAction(window);
        }

        if (!gameState.isGatherQuest()) {
            return new GatherTaskBoxAction(window);
        }

        if (!gameState.isGatherProp()) {
            return new GatherPropAction(window);
        }
        return new DelayAction(window, 1000);
    }

    @Override
    public String getName() {
        return "初始化游戏";
    }

    @Override
    public int getPriority() {
        return 5;
    }

    @Override
    public boolean isApplicable(IWindow window) {
        GameState gameState = window.getState().getGameState();
        boolean isInit = gameState.isGatherRole() && gameState.isGatherProp() && gameState.isGatherQuest() && gameState.isGatherPet();
        return window instanceof GameWindow && !isInit;
    }
}
